{% extends "base_sub.html" %}

{% block body_html %}
<div id="hd">

    <h1 id="hd_h1"></h1>
    <div id="skip_to_container"><a href="#container">转到文本</a></div>

    {% include "/bbs/newwin.inc.html" ignore missing %}

    {% set current_login_count=request.state.template_data.current_login_count %}
    <div id="tnb">
        <div class="inner">
            <ul id="hd_qnb">
                <li><a href="{{ url_for('faq_view') }}">FAQ</a></li>
                <li><a href="{{ url_for('qa_list') }}">Q&A</a></li>
                <li><a href="/bbs/new">新写作</a></li>
                <li>
                    <a href="/bbs/current_connect" class="visit">
                        联系人
                        <strong class="visit-num">{{ current_login_count|number_format }}</strong>
                    </a>
                </li>
            </ul>
        </div>
    </div>

    <div id="hd_wrapper">

        <button type="button" id="opener_aside" class="opener">
            <i class="fa fa-bars" aria-hidden="true"></i>
            <span class="blind">打开</span>
        </button>

        <a href="/" id="logo"><img src="/static/img/logo_gnuboard6.png" alt="nouboard6"></a>

        <button type="button" id="opener_header_search" class="opener">
            <i class="fa fa-search" aria-hidden="true"></i>
            <span class="blind">用户菜单</span>
        </button>

        <div id="header_search">
            <fieldset>
                <legend>网站内的全面搜索</legend>

                <form name="fsearchbox" method="get" action="/bbs/search" onsubmit="return fsearchbox_submit(this);">
                    <input type="hidden" name="sfl" value="wr_subject||wr_content">
                    <input type="hidden" name="sop" value="and">
                    <label for="sch_stx" class="blind">需要搜索字词</label>
                    <input type="text" name="stx" id="sch_stx" maxlength="20" placeholder="请输入您的搜索词">
                    <button type="submit" id="sch_submit" value="搜索"><i class="fa fa-search" aria-hidden="true"></i><span class="blind">搜索</span></button>
                </form>

                <script>
                function fsearchbox_submit(f)
                {
                    var stx = f.stx.value.trim();
                    if (stx.length < 2) {
                        alert("请输入两个以上的字母进行搜索.");
                        f.stx.select();
                        f.stx.focus();
                        return false;
                    }

                    var cnt = 0;
                    for (var i = 0; i < stx.length; i++) {
                        if (stx.charAt(i) == ' ')
                            cnt++;
                    }

                    if (cnt > 1) {
                        alert("对于快速搜索，您只能在搜索词中输入一个空格.");
                        f.stx.select();
                        f.stx.focus();
                        return false;
                    }
                    f.stx.value = stx;

                    return true;
                }
                </script>
            </fieldset>

            {% include "/bbs/popular.html" ignore missing %}
        </div>

        <script>
        $(function() {
            var openerAside = $("#opener_aside");
            var openerHeaderSearch = $("#opener_header_search");
            var closerAside = $("#closer_aside");
            var headerSearch = $("#header_search");
            var aside = $("#aside");

            openerHeaderSearch.on("click", function() {
                headerSearch.toggleClass("active");
            });

            openerAside.on("click", function() {
                aside.show();
            });

            closerAside.on("click", function() {
                aside.hide();
            });

        });
        </script>

        <div class="profile_wrap">
            <span class="profile_img" tabindex="0">
                <img src="{{ get_member_image(request.state.login_member.mb_id)|safe }}" alt="profile_image">
            </span>
            <ul class="hd_login">
                {% if request.state.login_member %}
                <li><a href="/bbs/member_confirm?url=/bbs/register_form">信息更正</a></li>
                {% if request.state.is_super_admin %}
                <li class="tnb_admin"><a href="/admin">经理</a></li>
                {% endif %}
                <li><a href="/bbs/logout">在日志之外</a></li>
                {% else %}
                <li><a href="/bbs/register">成员资格</a></li>
                <li><a href="/bbs/login">登录</a></li>
                {% endif %}
            </ul>
        </div>

    </div>

    <script>
        var profileImg = document.querySelector(".profile_wrap .profile_img");
        var mypageBox = document.querySelector(".hd_login");

        function handleProfileClick() {
        mypageBox.classList.add("active");
        }

        function handleProfileFocusout() {
        mypageBox.classList.remove("active");
        }

        profileImg.addEventListener("click", handleProfileClick);
        profileImg.addEventListener("focusout", handleProfileFocusout);
    </script>

</div>

{% if errors %}
<ul>
    {% for error in errors %}
    <li>{{ error }}</li>
    {% endfor %}
</ul>
{% endif %}

<hr>

<div id="wrapper">

    <div id="container">
        <h2 id="container_title"><span>{% block subtitle %}{% endblock subtitle %}</span></h2>
        {% block content %}
        {% endblock content %}
    </div>

    <div id="aside">
        <button type="button" id="closer_aside">
            <i class="fa fa-xmark" aria-hidden="true"></i>
            <span class="blind">全视图关闭</span>
        </button>

        {% if request.state.login_member %}
            {% include "/bbs/outlogin_after.html" %}
        {% else %}
            {% include "/bbs/outlogin_before.html" %}
        {% endif %}

        <!-- 用户页面菜单 -->
        {% include "/bbs/menu.html" ignore missing %}

        <!-- 最近的投票正在进行中 1枪 -->
        {% include "/bbs/poll.html" ignore missing %}

        <!-- 访客的拼贴 -->
        {% include "/visit/basic.html" ignore missing %}
    </div>

</div>

<hr>

<div id="ft">

    <div id="ft_wr">
        <div id="ft_link" class="ft_cnt">
            <a href="{{ url_for('content_view', co_id='company') }}">公司介绍</a>
            <a href="{{ url_for('content_view', co_id='privacy') }}">个人信息处理政策</a>
            <a href="{{ url_for('content_view', co_id='provision') }}">服务条款和条款</a>
            {% if not request.state.is_responsive %}
                {% if request.state.is_mobile %}
                    <a href="{{ url_for('device_change', device='pc') }}">PC版本</a>
                {% else %}
                    <a href="{{ url_for('device_change', device='mobile') }}">移动版</a>
                {% endif %}
            {% endif %}
        </div>
    </div>

    <div id="ft_copy">Copyright &copy; <b>{{ request.url.hostname }}.</b> All rights reserved.</div>

    <button type="button" id="top_btn">
        <i class="fa fa-arrow-up" aria-hidden="true"></i><span class="blind">到顶部</span>
    </button>
    <button type="button" id="darkmode-toggle-switch">
      <i class="fa-solid fa-moon visible bright"></i>
      <i class="fa-solid fa-sun visible dark"></i>
    </button>

</div>

{% if request.state.config.cf_analytics %}
    {{ request.state.config.cf_analytics|safe }}
{% endif %}

<script>

    $(function() {
        $("#top_btn").on("click", function() {
            $("html, body").animate({scrollTop:0}, '500');
            return false;
        });
    });

</script>
{% endblock body_html %}